package com.dq.domain.sys.user.user.centre;

import com.dq.domain.base.BaseEntity;
import com.dq.domain.sys.section.SysSection;
import com.dq.utils.TimeUtil;
import com.dq.vo.baseVo.VO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * @Author luchangtong
 * @Date 2020/4/10 13:58
 */
@Data
@Entity
@ApiModel("工作总结")
public class UserSummary extends BaseEntity implements VO.ToVO {
    @ApiModelProperty("所属门店")
    @ManyToOne
    protected SysSection section;
    @ApiModelProperty("反馈")
    protected String feedback;
    @ApiModelProperty("提交的业绩金额")
    protected BigDecimal price;

    @ApiModelProperty("年")
    @NotNull
    protected Long year;
    @ApiModelProperty("月")
    @NotNull
    protected Long month;
    @ApiModelProperty("ri")
    @NotNull
    protected Long day;


    @Data
    @ApiModel(value = "视图")
    public static class Vo implements VO {
        protected Long id;
        @ApiModelProperty("反馈")
        protected String feedback;
        @ApiModelProperty("提交的业绩金额")
        protected BigDecimal price;

        @ApiModelProperty("目标")
        protected BigDecimal target;
        @ApiModelProperty("完成")
        protected BigDecimal finish;
        @ApiModelProperty("剩余")
        protected BigDecimal residue;

        @ApiModelProperty("年")
        protected Long year;
        @ApiModelProperty("月")
        protected Long month;
        @ApiModelProperty("ri")
        protected Long day;

        @ApiModelProperty(value = "创建人")
        private Long createUserId;
        private String createUserName;
        @ApiModelProperty(value = "所属店铺")
        private Long sectionId;
        private String sectionName;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.feedback = this.getFeedback();
        vo.price = fmt(this.getPrice());

        vo.year = fmt(this.getYear());
        vo.month = fmt(this.getMonth());
        vo.day = fmt(this.getDay());

        vo.createUserId = this.getCreateUser() == null ? null : this.getCreateUser().getId();
        vo.createUserName = this.getCreateUser() == null ? "" : this.getCreateUser().getUserRealcName();
        vo.sectionId = this.getSection() == null ? null : this.getSection().getId();
        vo.sectionName = this.getSection() == null ? "" : this.getSection().getSimpleName();
        vo.createTime = fmt(this.getCreateTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        return vo;
    }
}
